package com.wtf.dsp.admin.controller;



import com.wtf.dsp.admin.model.dto.*;
import com.wtf.dsp.admin.model.vo.TemplateConfigVo;
import com.wtf.dsp.admin.service.CodeTemplateService;
import com.wtf.dsp.core.api.R;
import com.wtf.dsp.core.util.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * date: 2022/6/18 10:59
 * @author linhuanyou
 * @email 496558736@qq.com
 * @version 1.0
 */
@Api(tags = "代码模板")
@RestController
@RequestMapping("/code/template")
public class CodeTemplateController {

    @Autowired
    private CodeTemplateService codeTemplateService;

    @ApiOperation(value = "获取模板配置(分页)")
    @GetMapping("/page")
    public R page(@Validated TemplatePageDTO templatePageDTO){
        PageUtils page = codeTemplateService.page(templatePageDTO);
        return R.ok(page);
    }

    @ApiOperation(value = "获取模板配置")
    @GetMapping("/list")
    public R list(@Validated TemplateListDTO templateListDTO){
        List<TemplateConfigVo> list = codeTemplateService.list(templateListDTO);
        return R.ok(list);
    }

    @ApiOperation(value = "获取模板配置")
    @GetMapping("/info/{id}")
    public R<TemplateConfigVo> info(@PathVariable Integer id){
        TemplateConfigVo templateConfigVo = codeTemplateService.info(id);
        return R.ok(templateConfigVo);
    }

    @ApiOperation(value = "新增模板配置")
    @PostMapping("/add")
    public R save(@RequestBody @Validated TemplateAddDTO templateAddDTO){
        int save = codeTemplateService.add(templateAddDTO);
        return R.ok(save);
    }

    @ApiOperation(value = "更新模板配置")
    @PostMapping("/update")
    public R update(@RequestBody @Validated TemplateUpdateDTO templateUpdDTO){
        int update = codeTemplateService.update(templateUpdDTO);
        return R.ok(update);
    }

    @ApiOperation(value = "删除模板配置")
    @PostMapping("/del")
    public R remove(@RequestBody @Validated TemplateDelDTO templateDelDTO){
        int del = codeTemplateService.remove(templateDelDTO);
        return R.ok(del);
    }

}
